<?php
session_start();
include "../../include/dbFunctions.php";
include("../../include/mail/mailFunctions.php");
$eid = $_SESSION['eid'];
$query1 = "UPDATE event
            SET event_status = 'pending'
            WHERE event_id = $eid";
$result1 = executeQuery($query1);
if ($result1!=0) {
    //get data
    $query2 = "SELECT e.contact_id, c.contact_email FROM event e, contact_school c
    WHERE e.event_id=$eid
    AND e.contact_id = c.contact_school_id";
    $contact_a = executeSelectQuery($query2);
    $cid = $contact_a[0]['contact_id'];
    //sendemails
    $template = templateSchoolConfirm($cid,$eid);
    $to = $contact_a[0]['contact_email'];
    $subject = $template['title'];
    $message = $template['content'];
    $headers = "From: hauyee.ng@ja.org" . "\r\n" .
            "Reply-To: hauyee.ng@ja.org" . "\r\n" .
            "X-Mailer: PHP/" . phpversion();
    $sendresult = mail($to, $subject, $message, $headers);
    //$sendresult=1;
    if ($sendresult){
        $_SESSION['mes'] = 'Email has been sent to school representative.';
    }
}
if ($result1!=0) {
    $_SESSION['mes'].=" The record has been updated successfully";
    header('Location: ' . $_SERVER['HTTP_REFERER']);
} else {
    $_SESSION['mes']="Error! Please try again";
    header('Location: ' . $_SERVER['HTTP_REFERER']);
}
?>
